package edu.must.uh.impl;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.must.uh.util.JedisUtil;
import edu.must.uh.util.SqlUtils;
import edu.must.uh.util.PageBean;
import edu.must.uh.util.R;
import edu.must.uh.util.Tools;
import edu.must.uh.util.ToolsOfString;

public class BaseImpl {
    
    protected  String cashkey = " "; 
    protected  String cashListkey = " "; 
    protected  String keyFields =" ";
    protected  String tableName =" "; 
    
    
    public String getCashkey() {
        return cashkey;
    }

    public void setCashkey(String cashkey) {
        this.cashkey = cashkey;
    }

    public PageBean _PageBean = null;
    
    public Integer update(Object bean,String keyValue) throws Exception   { 
       // JedisUtil.del(cashkey);
        return SqlUtils.getMySqlInstance().update(tableName,bean,keyFields,keyValue);  
    }     
    
    public Integer update(String sql) throws Exception 
    { 
       //  JedisUtil.del(cashkey);
         return SqlUtils.getMySqlInstance().update(sql);
    }
    
    public Map<String,Object> getMap(String sql) throws Exception 
    { 
       //  JedisUtil.del(cashkey);
         return SqlUtils.getMySqlInstance().getMap(sql);
    }
    
    public Integer save(String sql) throws Exception 
    { 
       //  JedisUtil.del(cashkey);
         return SqlUtils.getMySqlInstance().save(sql);
    }
    
    
    public List<Map<String,Object>> ExistField(String controlId,String keydata,String keyValue) throws Exception   {       
         String keywordSQL ="";
         if(Tools.notEmpty(keyValue)) {
             keywordSQL = "AND "+keyFields+" <> '" + keyValue +"' ";   
         }  
         String sqlString= "SELECT 1 from " + tableName + " where 1 = 1 AND "+controlId+" ='"+keydata+"'" + keywordSQL;         
         return SqlUtils.getMySqlInstance().getlist(sqlString); 
    }
    
    
    public List<Map<String,Object>> getList(String sqlString) throws Exception   { 
        return SqlUtils.getMySqlInstance().getlist(sqlString); 
    }
    
    public Integer delete(String keyValue) throws Exception   { 
       // JedisUtil.del(cashkey);
        return SqlUtils.getMySqlInstance().delete(tableName,keyFields,keyValue);  
    }
    
    public Integer deleteByCondition(Map<String, Object> searchcondition) throws Exception   { 
     //   JedisUtil.del(cashkey);
        if(searchcondition !=null && !searchcondition.isEmpty()) {
            String sqlString = "UPDATE "+tableName+" SET DeleteMark = 1 Where DeleteMark = 0 ";             
            sqlString = sqlString + Tools.getSQLCondition(searchcondition); 
            return SqlUtils.getMySqlInstance().update(sqlString);
        }
        return 0;  
    }
    
    public Integer disAble(String keyValue) throws Exception   { 
      //  JedisUtil.del(cashkey);
        return SqlUtils.getMySqlInstance().disOrEnAble(tableName,"0",keyFields,keyValue);  
    }
    
    public Integer enAble(String keyValue) throws Exception   { 
      //  JedisUtil.del(cashkey);
        return SqlUtils.getMySqlInstance().disOrEnAble(tableName,"1",keyFields,keyValue);  
    }
}
